﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Subtle.ViewModels;
using Subtle.Domain.Services.Interfaces;

namespace Subtle.Controllers
{
	public class PostController : BaseController
	{
		private IPostService postService;

		/// <summary>
		/// Initializes a Post Controller
		/// </summary>
		/// <param name="postService"></param>
		public PostController(IPostService postService)
		{
			this.postService = postService;
		}

		/// <summary>
		/// Post/Index/{id}
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public ActionResult Index(string id)
		{
			return View(HomePostViewModel.GetModel(postService.GetPost(id)));
		}

		/// <summary>
		/// Post/Posts{year, month}
		/// </summary>
		/// <param name="year"></param>
		/// <param name="month"></param>
		/// <returns></returns>
		public ActionResult Posts(int year, int month)
		{
			IList<HomePostViewModel> homePostViewModels = (from archivedPost in postService.GetPosts(year, month)
														   select HomePostViewModel.GetModel(archivedPost)).ToList<HomePostViewModel>();
			return View(homePostViewModels);
		}
	}
}
